package domain.jdbc;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * 页码封装类
 * 
 * */
public class PageBean<T> {
	private static final Integer MAXPAGE=8;//最多显示几页
	private Integer pageSize;//每页记录数
	private Integer nowPage;//当前页码
	private Integer rowCount;//总记录数
	private List<T> items;//查询到的数据
	private String tName;//表名
	public PageBean() {
	}
	public PageBean(Integer pageSize,Integer nowPage) {
		this.pageSize=pageSize;
		this.nowPage=nowPage;
	}
	public Integer getRowCount() {
		return rowCount;
	}
	public void setRowCount(Integer rowCount) {
		this.rowCount = rowCount;
	}
	public String gettName() {
		return tName;
	}
	public void settName(String tName) {
		this.tName = tName;
	}
	public PageBean(String tName, int pageSize, Integer nowPage) {
		this.tName=tName;
		this.pageSize=pageSize;
		this.nowPage=nowPage;
	}
	public List<T> getItems() {
		return items;
	}
	public void setItems(List<T> items) {
		this.items = items;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getNowPage() {
		return nowPage;
	}
	public void setNowPage(Integer nowPage) {
		this.nowPage = nowPage;
	}
	
	//第一页
	public Integer getFirstPage(){
		return 1;
	}
	//上一页
	public Integer getPreviousPage(){
		return nowPage<=1?1:nowPage-1;
	}
	//下一页
	public Integer getNextPage(){
		return nowPage>=getPageCount()?getPageCount():nowPage+1;
	}
	//最后一页
	public Integer getLastPage(){
		return getPageCount();
	}
	
	//总页数
	public Integer getPageCount(){
		return (rowCount+pageSize-1)/pageSize;
		//return 20;
	}
	
	//获得页数项目1 2 3 4
	public List<Integer> getPageItems(){
		List<Integer> list=new ArrayList<Integer>();
		Integer startPage=1;
		Integer length=this.getPageCount();
		if(this.getPageCount()>=MAXPAGE){
			startPage=this.nowPage+MAXPAGE>this.getPageCount()?this.getPageCount()-MAXPAGE:this.nowPage;
			length=this.nowPage+MAXPAGE>this.getPageCount()?this.getPageCount():this.nowPage+MAXPAGE;
		}
		for (int i = startPage; i <=length; i++) {
			list.add(i);
		}
		return list;
	}
	
	@Override
	public String toString() {
		return "PageBean [pageSize=" + pageSize + ", nowPage=" + nowPage
				+ ", count=" + rowCount + ", items=" + items + ", tName=" + tName
				 + "]";
	}
	
	
}
